package com.hexa.wonderland.sdk;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import com.applovin.sdk.AppLovinMediationProvider;
import com.applovin.sdk.AppLovinPrivacySettings;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkConfiguration;
import com.applovin.sdk.AppLovinSdkInitializationConfiguration;
import com.hexa.wonderland.sdk.ad.HeMaxReward;
import com.hexa.wonderland.sdk.bridge.HeCocosBridge;
import com.hexa.wonderland.sdk.utils.HeUtils;

public class HeSDKManager {

    public static HeSDKManager getInstance() {
        return InstanceHolder.GAME_APPLICATION;
    }

    private static class InstanceHolder {
        private static final HeSDKManager GAME_APPLICATION = new HeSDKManager();
    }


    public void init(Activity activity) {
        Log.e("HexaW", "onCreateonCreate");
        Context mApplication = activity.getApplicationContext();

        HeBusiness.init(mApplication);

        initAppLovinPrivacySettings();
        
        AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder(
                        HeUtils.decrypt(HeConstant.MAX_KEY), mApplication)
                .setMediationProvider(AppLovinMediationProvider.MAX)
                .build();
        // Initialize the SDK with the configuration
        AppLovinSdk.getInstance(mApplication).initialize(initConfig, new AppLovinSdk.SdkInitializationListener() {
            @Override
            public void onSdkInitialized(final AppLovinSdkConfiguration config) {
//                AppLovinSdk.getInstance(context).showMediationDebugger();
                Log.e("HexaW", "onSdkInitialized");
                HeMaxReward.getInstance().loadRewardAd(mApplication);
            }
        });

        HeCocosBridge.getInstance().setMainGameActivity(activity);
    }

    private void initAppLovinPrivacySettings() {
        AppLovinPrivacySettings.setHasUserConsent(true);
        AppLovinPrivacySettings.setDoNotSell(false);
    }

    public static void showAd(String adSource){
        HeAdSdk.showBiddingAd(adSource);
    }
}
